﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using DataObjects.Interfaces;
using DataObjects.Enums;

namespace DataObjects.Behaviours
{
    abstract public class BaseBehaviour : IBehaviour
    {
        protected static readonly Random rand = new Random();
        protected BahaviourTypes bType;
        protected GameObject gameObj = null;

        public BaseBehaviour(GameObject gObject)
        {
            gameObj = gObject;
        }

        #region IBehaviour Members
        public void PreTurnProcessing()
        {
            InitialiseNewTurn();
            DetermineTurnPowerLevels();
            DetermineTurnTarget();
            DetermineTurnMovement();
        }

        public void ProcessTurn()
        {
            ProcessMovement();
            ProcessWeaponsFire();
        }

        public void PostTurnProcessing()
        {
            DetermineWeaponDamage();
        }

        public BahaviourTypes BahaviourType
        {
            get { return bType; }
            set { bType = value; }
        }

        public GameObject AssocitaedGameObject
        {
            get { return gameObj; }
            set { gameObj = value; }
        }
        #endregion

        #region Overridable Methods
        protected void InitialiseNewTurn()
        {
            gameObj.InitialiseNewTurn();
        }

        protected void DetermineTurnTarget()
        {
            gameObj.Target = GameMap.ClosestEnemyTo(gameObj).Id;
        }

        protected void DetermineTurnMovement()
        {
        }

        protected void ProcessMovement()
        {
        }

        protected void ProcessWeaponsFire()
        {
            gameObj.ProcessWeaponsFire();
        }

        protected void DetermineWeaponDamage()
        {
            gameObj.DetermineWeaponDamage();
        }

        abstract protected void DetermineTurnPowerLevels();
        #endregion

        public override string ToString()
        {
            return BahaviourType.ToString();
        }
    }
}
